import pymysql.cursors
from pymysql import Connection

conn = Connection(
    host="tenant-share-new-1.rwlb.rds.aliyuncs.com",
    password="ybDb#GWuF7n8",
    port=3306,
    user="yx_biz"
)

cursor = conn.cursor(pymysql.cursors.DictCursor)  # 返回字典格式

conn.select_db("tenant_share")  # 选择数据源

one_instance_tenants = [1583736627948580866, 1654314683914792961, 623168612024799233, 1669646531978604545,
                        1613440488390156289, 604,
                        1663458697050828801]

lastId = 0
count = 0
while True:
    sql = f"select * from history_order_by_product where tenant_id in (1583736627948580866, 1654314683914792961, 623168612024799233, 1669646531978604545,1613440488390156289, 604,1663458697050828801) and id > {lastId}  order by id asc limit 1000"

    cursor.execute(sql)

    result = cursor.fetchall()

    if len(result) == 0:
        break

    lastId = result[len(result) - 1]["id"]

    print(lastId)

    count += len(result)

    if len(result) < 1000:
        break

print("总条数：", count)
conn.close()
